package com.ebupt.migu.common.util;

import com.alibaba.fastjson.JSON;
import lombok.NoArgsConstructor;
import org.apache.kafka.common.serialization.Deserializer;

@NoArgsConstructor
public class JsonDeserializer<T> implements Deserializer<T> {

    private Class<T> targetClass;

    public JsonDeserializer(Class<T> targetClass) {
        this.targetClass = targetClass;
    }

    @Override
    public T deserialize(String topic, byte[] data) {
        if (data == null) {
            return null;
        }
        return JSON.parseObject(data, targetClass);
    }
}
